package chapter13;

import org.junit.Test;

import java.util.Arrays;
import java.util.regex.Pattern;


/**
 * @author : DuJiabao
 * @Date : 2021/2/23 10:43
 * @Project : thinking_in_java
 * @File : null.java
 * @Desc :
 */
public class splitTest {
  public static void main(String[] args) {
    String s = "the, next, then, when, what, why";
    System.out.println(Arrays.toString(s.split(" ")));  // [the,, next,, then,, when,, what,, why]
    System.out.println(Arrays.toString(s.split("\\W+")));  // [the, next, then, when, what, why]
  }

  //  通过Pattern分割
  @Test
  public void test() {
    String input = "This!!unusual use!!of exclamation!!points";
    Pattern c = Pattern.compile("!!");
    String[] split = c.split(input);
    System.out.println(Arrays.toString(split));

    // 限制分割字符串的个数
    String[] split1 = c.split(input, 3);
    System.out.println(Arrays.toString(split1));
  }
}
